#!/bin/bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DIR=$DIR/..
source $DIR/environment

if [ $# -lt 1 ]
  then
    echo "You should provide at least 1 args: path"
    exit 1
fi

$DIR/check

if grep -q DATABASE_URL docker-compose.yml ; then
    PYTESTOPT="--reuse-db -v"
else
    PYTESTOPT="-v"
fi

PACKAGE_PATH=$1

if [ $? -eq 0 ]; then
    if [ "$2" = "module" ]; then
        docker-compose run -e DJANGO_SETTINGS_MODULE -e TESTING=1 -w /polyaxon/${PACKAGE_PATH} scheduler py.test $PYTESTOPT ${@:3}
    else
        docker-compose run -e TESTING=1 -w /polyaxon/${PACKAGE_PATH} scheduler py.test $PYTESTOPT ${@:2}
    fi
fi
